Vue.filter("nyFilter", function (val) {
    var date = new Date(val);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    return y + "年" + m + "月"
});
Vue.filter("byFilter", function (val) {
    var date = new Date();
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    var str = y + "年" + m + "月";
    if (str == val) {
        return '本月'
    } else {
        return val;
    }
});
Vue.filter('timeFilter', function (val) {
    var date = new Date(val * 1000);
    var y = date.getFullYear()
    var m = date.getMonth() + 1;
    var d = date.getDate();
    var h = date.getHours();
    if ((h + "").length == 1) {
        h = "0" + h;
    }
    var mi = date.getMinutes();
    if ((mi + "").length == 1) {
        mi = "0" + mi;
    }
    var s = date.getSeconds();
    if ((s + "").length == 1) {
        s = "0" + s;
    }
    return y + "年" + m + "月" + d + "日  " + h + ":" + mi + ":" + s;
})
Vue.filter('typeFilter', function (val) {
    switch (val) {
        case '1':
            return '充值'
            break;
        case '2':
            return '提现'
            break;
        case '3':
            return '购买'
            break;
        case '4':
            return '出售'
            break;
        case '5':
            return '退款'
            break;
        case '6':
            return '冻结'
            break;
        case '7':
            return '解冻'
            break;
        case '8':
            return '发布'
            break;
        case '9':
            return '打赏'
            break;
        case '10':
            return '奖励'
            break;
        case '11':
            return '活动报名'
            break;

    }
})
var vm = new Vue({
    el: "#app",
    data: {
        page: 1, //当前页数
        show_trade_type: false, //展示交易类型选择面板
        now_trans_type: 'all',
        now_trans_name: '全部交易类型',
        trade_type_list: [{
                name: '全部',
                trans_type: 'all',
                istag: true
            },
            {
                name: '充值',
                trans_type: '1',
                istag: false
            },
            {
                name: '提现',
                trans_type: '2',
                istag: false
            },
            {
                name: '购买',
                trans_type: '3',
                istag: false
            },
            {
                name: '出售',
                trans_type: '4',
                istag: false
            },
            {
                name: '退款',
                trans_type: '5',
                istag: false
            },
            {
                name: '冻结',
                trans_type: '6',
                istag: false
            },
            {
                name: '解冻',
                trans_type: '7',
                istag: false
            },
            {
                name: '发布',
                trans_type: '8',
                istag: false
            },
            {
                name: '打赏',
                trans_type: '9',
                istag: false
            },
            {
                name: '奖励',
                trans_type: '10',
                istag: false
            },
        ],
        show_sz_type: false,
        now_sz_type: 'all',
        now_sz_name: '全部收支类型',
        sz_type_list: [{
                name: '全部',
                sz_type: 'all',
                istag: true
            },
            {
                name: '收入',
                sz_type: '1',
                istag: false
            },
            {
                name: '支出',
                sz_type: '0',
                istag: false
            },
        ],
        show_date_picker: false,
        minDate: new Date(2000, 0, 1),
        maxDate: new Date(2100, 10, 1),
        currentDate: new Date(),
        render_list: [], //渲染列表
        in_amount: '0', //总计收入
        out_amount: '0', //总计支出
        loading: false,
        finished: false,
        lock: false,
        search_key:'',//搜索框内容，订单号
        search_mode:false,//true标记为搜索模式
    },
    watch: {

    },
    methods: {
        choose_trade_type: function (item) {
            var that = this
            this.now_trans_type = item.trans_type;
            if (item.name == '全部') {
                this.now_trans_name = '全部交易类型'
            } else {
                this.now_trans_name = item.name;
            }
            this.trade_type_list.forEach(function (item) {
                item.istag = false;
            });
            item.istag = true;
            setTimeout(function () {
                that.close_trans_type();
                that.close_search();
                that.refresh_list();
            }, 500)
        },
        open_trans_type: function () {
            this.show_trade_type = true;
            this.show_sz_type = false;
        },
        close_trans_type: function () {
            this.show_trade_type = false;
        },
        toggle_trans_type: function () {
            if (this.show_trade_type) {
                this.close_trans_type()
            } else {
                this.open_trans_type();
            }
        },
        choose_sz_type: function (item) {
            var that = this;
            this.now_sz_type = item.sz_type;
            if (item.name == '全部') {
                this.now_sz_name = '全部收支类型'
            } else {
                this.now_sz_name = item.name;
            }
            this.sz_type_list.forEach(function (item) {
                item.istag = false;
            });
            item.istag = true;
            setTimeout(function () {
                that.close_sz_type();
                that.close_search();
                that.refresh_list();
            }, 500)
        },
        open_sz_type: function () {
            this.show_trade_type = false;
            this.show_sz_type = true;
        },
        close_sz_type: function () {
            this.show_sz_type = false;
        },
        toggle_sz_type: function () {
            if (this.show_sz_type) {
                this.close_sz_type()
            } else {
                this.open_sz_type();
            }
        },
        open_date_picker: function () {
            this.show_date_picker = true;
        },
        close_date_picker: function () {
            this.show_date_picker = false;
        },
        formatter(type, val) {
            if (type === 'year') {
                return `${val}年`;
            } else if (type === 'month') {
                return `${val}月`;
            }
            return val;
        },
        get_list: function (suc, err) {
            var that = this;
            var value = {
                page: that.page,
                date: that.chuli_date()
            };
            if (that.now_trans_type != 'all') {
                value.trans_type = that.now_trans_type;
            }
            if (that.now_sz_type != 'all') {
                value.payment_type = that.now_sz_type;
            }
            // 搜索模式
            if(that.search_mode){
                value = {
                    oid:that.search_key,
                    page:that.page
                }
            }
            $.post('/view/api_card/wallet_log', value, function (ret) {
                if (ret.code == '1') {
                    var data = ret.data.result;
                    for (var i = 0; i < data.length; i++) {
                        that.render_list.push(data[i]);
                    };
                    that.in_amount = ret.data.total.in;
                    that.out_amount = ret.data.total.out;
                    that.page++;
                    if (typeof suc == 'function') {
                        suc(ret)
                    }
                } else {
                    if (typeof err == 'function') {
                        err(ret);
                    }
                }
            })
        },
        chuli_date: function () {
            var date = this.currentDate;
            var y = date.getFullYear();
            var m = (date.getMonth() + 1) + '';
            if (m.length == 1) {
                m = '0' + m;
            }
            var str = y + '-' + m;
            return str;
        },
        open_loading: function () {
            var that = this;
            setTimeout(function () {
                that.loading = false;
                that.lock = true;
            }, 500)
        },
        onLoad: function () {
            var that = this;
            if (!that.lock) {
                return;
            }
            that.get_list(suc, err);

            function suc(ret) {
                that.open_loading();
            };

            function err(ret) {
                that.loading = false;
                that.finished = true;
                that.open_loading();
            }
        },
        date_confirm: function () {
            this.close_search();
            this.refresh_list();
        },
        refresh_list: function () {
            var that = this;
            that.lock = false;
            that.loading = false;
            that.finished = false;
            that.render_list = [];
            that.page = 1;
            app.toastLoading();
            that.get_list(suc, err);
            function suc(ret) {
                app.toastClear();
                that.open_loading();
            };

            function err(ret) {
                app.toastClear();
                that.open_loading();
                that.loading = false;
                that.finished = true;
            }
        },
        // 限制：输入框只能输入数字
        xianzhi:function(){
            this.search_key = this.search_key.replace(/[^\d]/g,'');
        },
        // 搜索
        search:function(){
            // 开启搜索模式标识
            // this.currentDate = new Date();
            this.search_mode = true;
            this.refresh_list();
        },
        //关闭搜索模式
        close_search:function(){
            this.search_mode = false;
            this.search_key = '';
        },
        init: function () {
            this.refresh_list();
        }
    },
    mounted: function () {
        this.init();
    }
});


// jQuery代码
$(document).ready(function () {
    $("#allBusiness").click(function () {
        // $(".rightShade").slideUp();
        // $(".leftShade").slideToggle();
    });
    // $(".leftShade").click(function(){
    //     $(".rightShade").slideUp();
    //     $(".leftShade").slideToggle();
    // });

    $("#allPay").click(function () {
        // $(".leftShade").slideUp();
        // $(".rightShade").slideToggle();
    });
    $(".rightShade").click(function () {
        // $(".leftShade").slideUp();
        // $(".rightShade").slideToggle();
    });

    // 选择月份插件
    // new Rolldate({
    //     el: "#date",
    //     format: "YYYY-MM",
    //     beginYear: 2000,
    //     endYear: 2100,
    //     theme: "blue",
    //     tapBefore: function(el) {
    //         console.log("插件开始触发");
    //     },
    //     moveEnd: function(el, iscroll) {
    //         console.log("滚动结束");
    //     },
    //     confirmBefore: function(el, date) {
    //         console.log("确定按钮触发");
    //     },
    //     confirmEnd: function(el, date) {
    //         console.log("插件运行结束");
    //     }
    // });
});


// 控制遮罩层的高度
var bodyHeight = document.getElementsByTagName("body")[0];
if (bodyHeight.clientHeight >= 700) {
    var leftShade = document.querySelectorAll(".leftShade")[0];
    var rightShade = document.querySelectorAll(".rightShade")[0];
    var headerHeight = document.getElementsByTagName("header")[0];
    leftShade.style.height = Number(bodyHeight.clientHeight) - Number(headerHeight.clientHeight) + "px";
    rightShade.style.height = Number(bodyHeight.clientHeight) - Number(headerHeight.clientHeight) + "px";

    // console.log(headerHeight.clientHeight);
    // console.log(bodyHeight.clientHeight);
    // console.log(Number(bodyHeight.clientHeight) - Number(headerHeight.clientHeight));
}